import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'person.dart';
import 'animal.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  MyHomePage({super.key});

  // 实例化类

  var p = Person();
  var a = Animal("xiao mao", 2).obs;

  // final RxInt _counter = 0.obs; // ①
  final RxInt _counter = RxInt(0); // ②
  // final RxString _username = 'zhangsan'.obs;
  final Rx<String> _username = Rx<String>('zhangsan'); // ③
  final RxList _list = ['张三', '里斯'].obs;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Flutter Dome")),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Obx(
              () => Text(
                "$_counter",
                style: Theme.of(context).textTheme.headlineLarge,
              ),
            ),
            SizedBox(height: 20),
            Obx(
              () => Text(
                _username.value,
                style: Theme.of(context).textTheme.headlineMedium,
              ),
            ),
            SizedBox(height: 20),
            Obx(
              () => Column(
                children: _list.map((v) => ListTile(title: Text(v))).toList(),
              ),
            ),
            SizedBox(height: 20),
            Obx(
              () => Text("${p.username}"),
            ),
            SizedBox(height: 20),
            Obx(
              () => Text(a.value.username),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          _counter.value++;
          _username.value = "lisi";
          _list.add("王武");
          p.username.value = p.username.value.toUpperCase();
          a.value.username = "xiaogou";
          a.value = a.value;
        },
        child: Icon(Icons.add),
      ),
    );
  }
}
